home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
EXGRAF3D
/
BOXSPHER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-27
|
3KB
|
166 lines
/*╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ÑÑÑ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤*/
/* */
/* BoxSphere.c -- Translation of Pascal 'LISA/EXAMPLE/BOXSPHERE.TEXT' */
/* from Apple Programmer's and Developer's Association */
/* disk 'Macintosh Example Applications and Sources v.1.0' */
/* */
/* Translation to LightSpeed C by Lewis E. Garrett - 9/27/90 */
/* CIS 71147,2202 */
/* */
/* */
/*╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ÑÑÑ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤*/
#include "Graf3D.h"
/* CONST */
#define keyOrMouse mDownMask+keyDownMask
#define NIL 0L
/* GrafPort gPort; */
Port3D gPort3D;
Fixed sinTable[31]; /*24 steps, 15 degree increments*/
EventRecord dummy;
Rect inRect;
WindowPtr w;
Port3D *ptr3D;
main()
{ /* main program */
FlushEvents(everyEvent, 0);
InitGraf(&thePort);
ptr3D = &gPort3D;
InitGrf3D(&ptr3D);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(NIL);
InitCursor();
HideCursor();
w = NewWindow(NIL, &screenBits.bounds, "\p", TRUE, 2, (WindowPtr)(-1L), FALSE, 0L);
SetPort(w);
PenPat(white);
BackPat(black);
EraseRect(&thePort->portRect);
Draw3D();
ShowCursor();
DisposeWindow(w);
}
Draw3D()
{
Open3DPort(&gPort3D);
InitSinTable();
FrameRect(&thePort->portRect);
inRect = thePort->portRect;
InsetRect(&inRect, 1, 1);
LookAt(-983040, 655360, 983040, -655360); /*LookAt (-15, 10, 15, -10)*/
ViewAngle(1966080); /*ViewAngle(30)*/
Roll(1310720); /*Roll(20)*/
Pitch(4915200); /*Pitch(75)*/
do {
EraseRect(&inRect);
Yaw(327680); /*Yaw(5)*/
DrawCube(1048576); /*DrawCube(16)*/
DrawSphere(524288); /*DrawSphere(8)*/
}
while (!GetOSEvent(keyOrMouse, &dummy));
}
InitSinTable()
{
/* CONST */
#define f15DivRad 17157L
int iAng;
for ( iAng = 0; iAng<=30; iAng++ ) {
sinTable[iAng] = FixDiv(FracSin(FixMul(FixRatio(iAng, 1),
f15DivRad)), 1073741824);
}
}
DrawCube(Edge)
Fixed Edge;
{
Fixed Half;
Half = FixDiv (Edge, 131072); /*Half := Edge / 2*/
Move3D(-Half,-Half,-Half);
Line3D(0,Edge,0);
Line3D(Edge,0,0);
Line3D(0,-Edge,0);
Line3D(-Edge,0,0);
Move3D(0,0,Edge);
Line3D(0,Edge,0);
Line3D(Edge,0,0);
Line3D(0,-Edge,0);
Line3D(-Edge,0,0);
Move3D(0,0,-Edge);
Line3D(0,0,Edge);
Move3D(0,Edge,-Edge);
Line3D(0,0,Edge);
Move3D(Edge,0,-Edge);
Line3D(0,0,Edge);
Move3D(0,-Edge,-Edge);
Line3D(0,0,Edge);
Move3D(-Half,Half,-Half);
}
Circle(radius)
Fixed radius;
{
Fixed xCenter,
yCenter,
ang;
int iAng;
xCenter = gPort3D.pen.x;
yCenter = gPort3D.pen.y;
MoveTo2D(xCenter, yCenter+radius);
for ( iAng = 0 ; iAng<=24; iAng++ )
LineTo2D(xCenter + FixMul(radius, sinTable[iAng]),
yCenter + FixMul(radius, sinTable[iAng + 6]));
MoveTo2D(xCenter, yCenter);
}
DrawSphere(radius)
Fixed radius;
{
int zPlane;
Fixed zStep,
dz;
Point3D center;
/* WITH gPort3D */
center = gPort3D.pen;
zStep = FixDiv(radius, 524288); /*zStep := radius / 8;*/
for ( zPlane = -7 ; zPlane<=7; zPlane++ )
{
dz = FixMul(zStep, FixRatio(zPlane, 1));
MoveTo3D(center.x, center.y, center.z + dz); /*Get on the right plane.*/
Circle(FracSqrt(FixMul(radius, radius) - FixMul(dz, dz)) >> 7);
/*Draw a circle there.*/
}
MoveTo3D(center.x, center.y, center.z);
}